<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c"%>
<%
	String path = request.getContextPath();
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>账户账号 新增</title>
<jsp:include page="../../import.jsp" flush="true"/>
</head>
<body>
		<form id="mcrLoanAccount_form">
            <div class="fieldset1 tabel_col tabel_col_s clearFix noBorder">
                <div class="fieldBox col_50">
                    <div class="label">机构名称</div>
                    <div class="field">
                        <select name="loanId" id="loanId">
                        	<option value = ""></option>
	                        <c:forEach items="${channelList }" var="ct">
	                        	<option value="${ct.id }">${ct.loanName }</option>
	                        </c:forEach>
                    	</select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">账户名称</div>
                    <div class="field">
                        <input name="accountName" id="accountName" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:100}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">账户账号</div>
                    <div class="field">
                        <input name="accountNumber" id="accountNumber" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">开户行</div>
                    <div class="field">
                        <input name="accountBank" id="accountBank" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:100}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">开户行号</div>
                    <div class="field">
                        <input name="accountBankNo" id="accountBankNo" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">账户初始余额(元)</div>
                    <div class="field">
                        <input name="accountIniBalance" id="accountIniBalance" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">账户有效开始日期</div>
                    <div class="field">
                        <input name="accountStartdateStr" id="accountStartdateStr" type="text" class="ui-datepicker" value="" validate="{required:true, maxlength:500}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">账户有效截止日期</div>
                    <div class="field">
                        <input name="accountEnddateStr" id="accountEnddateStr" type="text" class="ui-datepicker" value="" validate="{required:true, maxlength:500}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">第一次结息日期</div>
                    <div class="field">
                        <input name="knotStarttimeStr" id="knotStarttimeStr" type="text" class="ui-datepicker" value="" validate="{required:true, maxlength:500}">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">结息间隔(月)</div>
                    <div class="field">
                        <input name="knotInterval" id="knotInterval" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">结息开始天数(日)</div>
                    <div class="field">
                        <input name="kontStartday" id="kontStartday" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">是否启用</div>
                    <div class="field">
                       <select name="isValid" id="isValid">
	                		<option value="1">是</option>
	                		<option value="0">否</option>
	                	</select>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">账户不动金额(元)</div>
                    <div class="field">
                        <input name="accountImmovAmount" id="accountImmovAmount" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">产品编码</div>
                    <div class="field">
                        <input name="productCode" id="productCode" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">信托贷款编号</div>
                    <div class="field">
                        <input name="loanCode" id="loanCode" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">信托合同编号</div>
                    <div class="field">
                        <input name="contractCode" id="contractCode" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">是否单一通道</div>
                    <div class="field">
                        <select name="singleChannel" id="singleChannel">
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">信托项目编号</div>
                    <div class="field">
                        <input name="projectCode" id="projectCode" type="text" class="ui-textbox" value="" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">资产编码</div>
                    <div class="field">
                        <input name="assetsCode" id="assetsCode" type="text" class="ui-textbox" value="" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">单笔金额(元)</div>
                    <div class="field">
                        <input name="simgleAmt" id="simgleAmt" type="text" class="ui-textbox" value="" validate="{required:true, maxlength:500, digits:true}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">*</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">支持客户</div>
                    <div class="field">
                        <select name="supportType" id="supportType">
                            <option value="0">内部</option>
                            <option value="1">外部</option>
                            <option value="2">全部</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">是否卓远担保</div>
                    <div class="field">
                        <select name="isGuarantee" id="isGuarantee">
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">是否真实担保合同</div>
                    <div class="field">
                        <select name="isRealGuaranteeCrt" id="isRealGuaranteeCrt">
                            <option value="1">是</option>
                            <option value="0">否</option>
                        </select>
                    </div>
                </div>
                 <div class="fieldBox col_50">
                    <div class="label">担保合同费率类型</div>
                    <div class="field">
                        <select name="guaranteeRateType" id="guaranteeRateType" onchange="switchGuaranteeRateForm()">
                            <option value="1">反算费率</option>
                            <option value="0">固定费率</option>
                        </select>
                    </div>
                </div>
                <div class="fieldBox col_50" style="display: none" id="mcrLoanAccountAdd_guaranteeRate">
                    <div class="label">固定担保年费率</div>
                    <div class="field">
                        <input name="guaranteeRateValue" id="guaranteeRateValue" type="text" class="ui-textbox" value=""  validate="{range:[0,100]}" onkeydown="return banInputSapce(event);" onKeyup="return inputSapceTrim(event,this);">
                        <span class="requiredSymbol">%</span>
                    </div>
                </div>
                <div class="fieldBox col_50">
                    <div class="label">是否单一通道</div>
                    <div class="field">
                        <select name="repoSubject" id="repoSubject">
                            <option value="0">无</option>
                            <option value="1">天津卓远融资担保有限公司</option>
                            <option value="2">狮桥融资租赁（中国）有限公司</option>
                        </select>
                    </div>
                </div>
                <%--<div class="fieldBox col_50">
                    <div class="label">合同模板</div>
                    <div class="field">
                        <input name="contCfgCd" id="contCfgCd" type="text" class="ui-textbox" value="" >
                    </div>
                </div>--%>
                <!-- hide data -->
		        <div class="fieldBox col_100" style="display:none;">
		          <div class="field">
		              <input name="dataId" id="dataId" type="text" class="ui-textbox" value="${id}">
		          </div>
		        </div>
            </div>
        </form>
	<script>
		$(function() {
		   $("#mcrLoanAccount_form").ligerForm({
                validate: true
           });

		  /*  if($("#dataId").val()){
			   $("#knotStarttimeStr").attr("disabled","true");
			   $("#knotStarttimeStr").removeAttr("class");
			   $("#knotStarttimeStr").attr("class","ui-textbox");
		   } */
	       initData();
		});
		
		//定义父级调用事件
		frameElement.dialog.onOk = function () {
			save();
		}
		
		frameElement.dialog.onCancel = function () {
			frameElement.dialog.close();
		}
		
		//保存
		function save(){
			var ligerForm = liger.get("mcrLoanAccount_form");
			var loanId = $("#loanId").val();
			var guaranteeRateType = $("#guaranteeRateType").val();
			var guaranteeRateValue = $("#guaranteeRateValue").val();

            if(loanId==''){
            	UIUtils.alertWarning("请选择机构!");
            	return;
            }
            if(guaranteeRateType=='0' && (guaranteeRateValue=='' || guaranteeRateValue==null)){
                UIUtils.alertWarning("请填写固定担保年费率!");
                return;
            }
            if (!ligerForm.valid()) {
                UIUtils.alertWarning("有验证信息未通过!");
                return; //验证不通过，不执行以下代码
            }
            var data = ligerForm.getData();
            var dataId = $("#dataId").val();
            var url = '<%=path%>/mcr/mcrLoanAccount/add.do';
            if(StringUtils.isNotEmpty(dataId)){
            	url = '<%=path%>/mcr/mcrLoanAccount/modify.do';
            	data["id"]= dataId;
            }
            AjaxUtils.ajaxPost(url, data, addCallback);
		}
		
		
		//新增回调
		function addCallback(msg){
			if(msg.success == 1){
				 parent.grid.reload();
				 //parent.$.ligerDialog.SQalert({content:'提示内容', SQ_type: "success"});
				 UIUtils.alertSuccess("操作成功!");
				 frameElement.dialog.close();
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//修改初始化数据
		function initData(){
			var dataId = $("#dataId").val();
	    	if(StringUtils.isEmpty(dataId))return;
	    	var _url = '<%=path%>/mcr/mcrLoanAccount/getById.do';
	    	AjaxUtils.ajaxGet(_url, {id:dataId}, initCallback);
    	}
		
		//初始化回调
		function initCallback(msg){
			if(msg.success == 1){
				 setData(msg.data);//设置数据
			 }else{
				 UIUtils.alertError(msg.info);
			 }
		}
		
		//修改时候设置页面数据
	    function setData(data){
	    	var form = new liger.get("mcrLoanAccount_form");
	    	form.setData({
	    		loanId:data.loanId,
	    		accountName:data.accountName,
	    		accountNumber:data.accountNumber,
	    		accountBank:data.accountBank,
	    		accountBankNo:data.accountBankNo,
	    		accountIniBalance:data.accountIniBalance,
	    		accountStartdateStr:data.accountStartdate,
	    		accountEnddateStr:data.accountEnddate,
	    		knotTime:data.knotTime,
	    		knotInterval:data.knotInterval,
	    		kontStartday:data.kontStartday,
	    		isValid:data.isValid,
	    		accountImmovAmount:data.accountImmovAmount,
	    		knotStarttimeStr:data.knotStarttime,
	    		productCode:data.productCode,
                projectCode:data.projectCode,
	    		loanCode:data.loanCode,
                simgleAmt:data.simgleAmt,
                supportType:data.supportType,
                singleChannel:data.singleChannel,
                assetsCode:data.assetsCode,
                contCfgCd:data.contCfgCd,
                contractCode:data.contractCode,
                isGuarantee:data.isGuarantee,
                isRealGuaranteeCrt:data.isRealGuaranteeCrt,
                guaranteeRateType:data.guaranteeRateType,
                guaranteeRateValue:data.guaranteeRateValue,
                repoSubject:data.repoSubject
	    	});
	    	if (data.guaranteeRateType == "0"){
                $("#mcrLoanAccountAdd_guaranteeRate").show();
            }
		};

        function switchGuaranteeRateForm(){
            var guaranteeRateType = $("#guaranteeRateType").val();
            if(guaranteeRateType=="1"){
                $("#mcrLoanAccountAdd_guaranteeRate").hide();
            }
            if(guaranteeRateType=="0"){
                $("#mcrLoanAccountAdd_guaranteeRate").show();
            }
        }

        /**
         * 是否去除所有空格
         * @param str
         * @param is_global 如果为g或者G去除所有的
         * @returns
         */
        function Trim(str,is_global)
        {
            var result;
            result = str.replace(/(^\s+)|(\s+$)/g,"");
            if(is_global.toLowerCase()=="g")
            {
                result = result.replace(/\s/g,"");
            }
            return result;
        }

        /**
         * 空格输入去除
         * @param e
         * @returns {Boolean}
         */
        function inputSapceTrim(e,this_temp)
        {
            this_temp.value = Trim(this_temp.value,"g");
            var keynum;
            if(window.event) // IE
            {
                keynum = e.keyCode
            }
            else if(e.which) // Netscape/Firefox/Opera
            {
                keynum = e.which
            }
            if(keynum == 32){
                return false;
            }
            return true;
        }

        /**
         * 禁止空格输入
         * @param e
         * @returns {Boolean}
         */
        function banInputSapce(e)
        {
            var keynum;
            if(window.event) // IE
            {
                keynum = e.keyCode
            }
            else if(e.which) // Netscape/Firefox/Opera
            {
                keynum = e.which
            }
            if(keynum == 32){
                return false;
            }
            return true;
        }
	</script>

</body>
</html>